<template>
	<view class="weui-grids menu-grid">
		<block v-for="(item,index) in wxArticleMenus" :key="index">
			<view @click="onMenuClick(item)">
				<view class="weui-grid menu-item">
					<image class="menu-image" :src="item.image"></image>
					<view class="weui-grid__label menu-item_label">{{item.name}}</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	import {
		wanAndArticles
	} from '@/router.js'
	export default {
		data() {
			return {
				wxArticleMenus: []
			}
		},
		onLoad() {
			this.getArticleMenus()
		},
		methods: {
			getArticleMenus() {
				uni.showLoading({
					title: '加载中',
				})
				uniCloud.callFunction({
					name: 'json-data',
					data: {
						action: "wanAndroid"
					},
					success: (res) => {
						wx.hideLoading()
						console.log(res)
						let result = res.result.data
						if (result && result.length > 0) {
							this.wxArticleMenus = result
						}
					}
				})
			},
			onMenuClick(menuItem) {
				console.log(menuItem)
				wx.navigateTo({
					url: wanAndArticles + `?menuId=${menuItem.id}&menuName=${menuItem.name}`
				})
			}
		}
	}
</script>

<style>
	.menu-grid {
		margin: 10px 15px;
	}

	.menu-item {
		width: 25%;
		padding: 5px 5px;
		text-align: center;
		border-right: 1rpx solid #e9e7ef;
		border-bottom: 1rpx solid #e9e7ef;
	}

	.menu-image {
		width: 50px;
		height: 50px;
		border-radius: 50%;
	}

	.menu-item_label {
		margin-top: 0px;
		font-size: 13px;
	}
</style>
